# 替换字符

def change_char(s: str, l, r, old, new):
    sub = s[l - 1:r]
    sub = sub.replace(old, new)
    pre, post = "", ""
    if l - 1 > 0:
        pre = s[:l - 1]
    if r - 1 < len(s):
        post = s[r:]
    return pre + sub + post


if __name__ == '__main__':
    s = input()
    n = int(input())
    for _ in range(n):
        l, r, old, new = input().split()
        s = change_char(s, int(l), int(r), old, new)
    print(s)
